(function ($) {
    var Good_List = {
        opts: {
            URL: 'article/getArticles'
        },
        init: function () {
            this.initEvents();
        },
        initEvents: function () {
            var content = this;

            // 检索显示列表
            $(".goods-filter").on("click", function (e) {
                e.preventDefault();

                var conditions = $("#goods_filter_form").serialize();

                $.tipsWarningAlert

                location.assign(content.opts.URL + '?' + conditions);
            });

            // 分页点击
            $(".page-first, .page-prev, .page-index, .page-next, .page-last").on("click", function (e) {
                e.preventDefault();

                var conditions = location.search;
                var pageIndex = $(this).attr("data-index");

                if (conditions) {
                    if (conditions.indexOf("page=") == -1) {
                        location.assign(content.opts.URL + '?' + conditions + '&page=' + pageIndex);
                    } else {
                        location.assign(content.opts.URL + '?' + conditions.replace(/(page=)\d+/, '$1' + pageIndex).replace('?',''));
                    }
                } else {
                    location.assign(getRootPath()+'/article/getArticles?page=' + $(this).attr("data-index"));
                }
            });

            $(".del_good").click(function () {
                var $this = $(this);
                if(window.confirm("确定删除吗？")){
                    $.post("article/deleteArticle", {articleId: $this.data('id')}, function(res){
                        if(res.code == 1){
                            window.location.replace(getRootPath()+'/article/getArticles?articleStatus=1');
                            $.tipsSuccessAlert('删除文章成功！')
                        }else{
                            $.logConsole('删除文章失败', res.message);
                            $.tipsWarningAlert(res.message || '删除文章失败');
                        }
                    });
                }
            });
        }
    };

    Good_List.init();
})(jQuery);
